package com.gzhryc.shared_device.oem.h5.mng.controllers.ops;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.gzhryc.common.data.dto.AjaxResult;
import com.gzhryc.servlet.DtoConstants;
import com.gzhryc.servlet.WebUtils;
import com.gzhryc.servlet.annotation.Route;
import com.gzhryc.shared_device.bxscn.code.outside.znst.OutsideZNSTConfig;
import com.gzhryc.shared_device.oem.code.ConfigUtils;

public class OutsideAPIConfigController {

    @Route("/ops/outside_api/index.html")
    public String setting(HttpServletRequest request, HttpServletResponse response, HttpSession session) {
        OutsideZNSTConfig config = ConfigUtils.getOutsideZNSTConfig();
        request.setAttribute("znstConfig", config);
        return "/ops/outside_api/setting.html";
    }

    @Route(value = { "/ops/outside_api/znst_config/update.do" })
    public AjaxResult updateSetting(HttpServletRequest request, HttpServletResponse response, HttpSession session) {
        AjaxResult result = new AjaxResult(DtoConstants.EXECUTE_ERROR, "修改失败");
        try {
            OutsideZNSTConfig config = WebUtils.getParameter(request, OutsideZNSTConfig.class);
            if (config != null){
                if (ConfigUtils.save(config)) {
                    result.setCode(DtoConstants.SUCCESS, null);
                }
            }
        } catch (Exception e) {
            result.setMsg(e.getMessage());
        }
        return result;
    }
}
